package org.scirp.ijmis.service.personpaper.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.scirp.ijmis.dao.personpaper.IJournalOfPersonDAO;
import org.scirp.ijmis.dao.personpaper.ILoginDAO;
import org.scirp.ijmis.po.personpaper.JournalOfPerson;
import org.scirp.ijmis.po.personpaper.Login;
import org.scirp.ijmis.po.personpaper.ResearchFieldOfPaper;
import org.scirp.ijmis.service.personpaper.ILoginService;
import org.scirp.ijmis.util.Pagination;

public class LoginServiceImpl implements ILoginService {

	private ILoginDAO loginDAO;
	private IJournalOfPersonDAO journalOfPersonDAO;
	public ILoginDAO getLoginDAO() {
		return loginDAO;
	}

	public void setLoginDAO(ILoginDAO loginDAO) {
		this.loginDAO = loginDAO;
	}

	public Boolean checkLoginNameAndPassword(String loginName, String MD5Password, long journalID) {
		Boolean result = false;

		if (this.selectLogin(loginName, MD5Password, journalID).size() != 0) {
			result = true;
		} else {
			result = false;
		}

		return result;

	}
	
	@Override
	public boolean checkLoginNameAndPassword(String loginName, String MD5Password) {
		return loginDAO.selectLogin(loginName, MD5Password);
	}
	public Long selectCountByRoleType(long roleId, long journalID) {
		return loginDAO.selectCountByRoleType(roleId, journalID);
	}
	public List<Login> selectLoginByRoleType(long roleId, long journalID,Pagination pagination){
		return loginDAO.selectLoginByRoleType(roleId, journalID,pagination);
	}
	public List<Login> selectLogin(String loginName, String MD5Password, long journalID) {
		return loginDAO.selectLogin(loginName, MD5Password, journalID);
	}

	public Login selectByPersonId(Long personId) {
		return loginDAO.selectByPersonId(personId);

	}

	public Boolean updatePassword(Long personId, String plainPassword, String MD5Password) {
		return loginDAO.passwordModification(personId, plainPassword, MD5Password);

	}

	public List<Login> selectAll() {
		return this.getLoginDAO().selectAll();
	}

	public Long countObject() {
		return this.getLoginDAO().countObject();
	}

	public Login selectById(Object id) {

		return (Login) this.getLoginDAO().selectById(id);
	}

	public long saveLogin(Login entity) {
		return this.getLoginDAO().saveLogin(entity);
	}
	public boolean saveEditor(Login login,List<JournalOfPerson> list) {
		boolean flag=true;
		if(login.getPerson()!=null&&login.getPerson().getPid()!=null){
			flag=flag&&journalOfPersonDAO.deleteJournalOfPersonByPersonId(login.getPerson().getPid());
		}
		for (JournalOfPerson journalOfPerson : list) {
			flag=flag&&(journalOfPersonDAO.saveJournalOfPerson(journalOfPerson)>0);
		}
		return flag&&loginDAO.updateLogin(login);
	}
	public boolean updateLogin(Login entity) {
		return this.getLoginDAO().updateLogin(entity);
	}

	public Login selectLoginByLoginName(String loginName) {
		return this.getLoginDAO().selectLoginByLoginName(loginName);
	}
	public Login selectExpertByEmailAndJournal(String email,Long journalId) {
		return loginDAO.selectExpertByEmailAndJournal(email, journalId);
	}
	public Login deleteLogin(Login entity) {
		return this.getLoginDAO().deleteLogin(entity);
	}

	public boolean deleteLoginByIds(Object[] idCollection) {
		return this.getLoginDAO().deleteLoginByIds(idCollection);
	}

	public Login selectLoginByLoginNameAndEmail(String loginName, String email) {
		return this.getLoginDAO().selectLoginByLoginNameAndEmail(loginName, email);
	}

	public Login selectLoginByLoginNameAndEmail(String loginName, String email, String answer) {
		// TODO Auto-generated method stub
		return this.getLoginDAO().selectLoginByLoginNameAndEmail(loginName, email, answer);
	}

	public Login selectLoginByLoginNameAndIdentifier(String loginName, String identifier) {
		return loginDAO.selectLoginByLoginNameAndIdentifier(loginName, identifier);
	}
	public List<Login> selectByCondition(long expertSourcesId, long researchFieldId, long journalID, long paperNo, String email, Pagination pagination){
		return loginDAO.selectByCondition(expertSourcesId, researchFieldId,journalID, paperNo, email, pagination);
	}
	public Long selectCountByCondition(long expertSourcesId, long researchFieldId, long journalID, long paperNo, String email){
		return loginDAO.selectCountByCondition(expertSourcesId, researchFieldId,journalID, paperNo, email);
	}
	
	public IJournalOfPersonDAO getJournalOfPersonDAO() {
		return journalOfPersonDAO;
	}

	public void setJournalOfPersonDAO(IJournalOfPersonDAO journalOfPersonDAO) {
		this.journalOfPersonDAO = journalOfPersonDAO;
	}

}
